<%--                                                                       --%>
<%-- Copyright (c) 2005 BroadVision, Inc.  All rights reserved.            --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<%
  String ctxPath = request.getContextPath();
%>

<script language="JavaScript">

//
//
//
function doChannelParentAdministratorsView(url) {
  var popupWindow = window.open(url, "epChannelParentAdministrators", 'width=700,height=600,scrollbars=yes,resizable=yes');
  if (popupWindow != null) {
    if (popupWindow.opener == null) {
      popupWindow.opener = self;
    }
  }
  popupWindow.focus();
}

//
//
//
function searchUserPopup(popupUrl, parentFormName, parentFieldName) {
  if (popupUrl != null) {
    if (popupUrl.indexOf("?") < 0) {
      popupUrl += "?";
    } 
    else {
      popupUrl += "&";
    }
  }
  popupUrl += 'parentFormName=' + parentFormName + '&parentFieldName=' + parentFieldName;

<c:if test="${not empty epChannelAdministratorsView.map.users}">
  var selected = "<c:forEach var="user" items="${epChannelAdministratorsView.map.users}" varStatus="index"><c:out value="${user.map.signinId}"/>%24%23@!</c:forEach>";
  popupUrl += "&selected=" + selected;
</c:if>

  var windowName = parentFormName + parentFieldName;
  var windowFeatures = 'width=700,height=600,scrollbars=yes,resizable=yes';
  var popupWindow = window.open(popupUrl, windowName, windowFeatures);
  if (popupWindow != null) {
    if (popupWindow.opener == null) {
      popupWindow.opener = self;
    }
  }
  popupWindow.focus();
}

//
//
//
function doUserSelect() {
  <c:url var="selectUrl" value="/mt/userMultiSearchPopup.do"/>

  searchUserPopup("<c:out value="${selectUrl}"/>", "epChannelAdministratorForm", "userNames");
}

//
//
//
function setSelectedUsers(formName, fieldName, users) {
  document.epChannelAdministratorsForm.userNames.length = 0;
  for (var index = 0; index < users.length; index++) {
    var option = new Option(users[index], users[index], true, true);
    document.epChannelAdministratorsForm.userNames.options[index] = option;
  }
  document.epChannelAdministratorsForm.submit();
}

//
//
//
function doUsersRemove(form) {
  form.action = "<c:url value="/ep/channelAdministratorRemove.do"/>";
  form.submit();
}

//
//
//
function doDone(form) {
  form.action = "<c:url value="/ep/cancel.do"/>";
  form.submit();
}

<%@ include file="/mc/common/jsutils.jsp" %>

</script>

<c:set var="removeImg">
<img src="<%= ctxPath %>/ep/images/action/icon_remove.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.remove" bundle="ep.messages"/>" title="<bean-el:message key="image.alt.remove" bundle="ep.messages"/>">
</c:set>

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
    <td valign="top" width="100%">
      <div class="pageTitle">
        <bean-el:message key="ep.channel.view.page.title" bundle="ep.messages" arg0="${epChannelAdministratorsView.map.name}"/>
      </div>
      <div class="errorMessage"><html-el:errors bundle="ep.messages"/></div>
      <%@ include file="/mc/common/pagetab.jsp" %>

      <!- place body here -->
      <!- add breadcrumb ->
     <div class="breadcrumb">
      <c:if test="${not empty epChannelAdministratorsView.map.breadcrumbs}">
        <c:forEach var="channel" items="${epChannelAdministratorsView.map.breadcrumbs}" varStatus="index">
          <c:url var="browseUrl" value="/ep/channelBrowse.do">
            <c:param name="channelId" value="${channel.map.id}"/>
          </c:url>
          <c:if test="${index.count > 1}"><bean-el:message key="ep.breadcrumb.delimiter" bundle="ep.messages"/>&nbsp;</c:if><a href="<c:out value="${browseUrl}"/>"><c:out value="${channel.map.name}"/></a>
        </c:forEach>
      </c:if>
      </div>
<c:url var="parentAdminsUrl" value="/ep/channelParentAdministratorsView.do">
  <c:param name="channelId" value="${epChannelAdministratorsView.map.id}"/>
</c:url>

      <div class="pageSubtitle">
        <span class="left"><bean-el:message key="ep.channel.administrators" bundle="ep.messages"/></span>
        <span class="right">
          <input type="button" class="inputButton" value="<bean-el:message key="button.inherited.administrators.view" bundle="ep.messages"/>" onclick="doChannelParentAdministratorsView('<c:out value="${parentAdminsUrl}"/>')">
<c:if test="${epChannelAdministratorsView.map.editable}">
          <input type="button" class="inputButton" value="<bean-el:message key="button.administrators.select" bundle="ep.messages"/>" onclick="doUserSelect()">
</c:if>
        </span>
      </div>


      <html-el:form action="/ep/channelAdministratorsSave.do">

      <input type="hidden" name="channelId" value="<c:out value="${epChannelAdministratorsView.map.id}"/>"/>
      <input type="hidden" name="ctx.f" value="<c:out value="${requestScope['ctx.f']}"/>"/>

      <select name="userNames" multiple="multiple" size="0"></select>
      <script language="JavaScript1.2">
      var theform = document.forms['epChannelAdministratorsForm'];
      theform.userNames.style.visibility = 'hidden';
      theform.userNames.style.display = 'none';
      </script>

      </html-el:form>

      <form action="<c:url value="/ep/channelAdministratorsView.do"/>" method="post">

      <input type="hidden" name="channelId" value="<c:out value="${epChannelAdministratorsView.map.id}"/>"/>
      <input type="hidden" name="ctx.f" value="<c:out value="${requestScope['ctx.f']}"/>"/>

<c:if test="${not empty epChannelAdministratorsView.map.users}">

  <c:if test="${epChannelAdministratorsView.map.editable}">
      <div class="globalButtonWrap">
        <input type="button" name="selectAllUsers" class="globalButton" value="<bean-el:message key="button.selectAll" bundle="ep.messages"/>"
          onclick="check(this.form.userIds, this);">
        <input type="button" class="globalButton" value="<bean-el:message key="button.remove" bundle="ep.messages"/>"
	  onclick="if (isAnyChecked(this.form.userIds, '<bean-el:message key="ep.users.atLeastOne" bundle="ep.messages"/>')) doUsersRemove(this.form);">
       </div>
  </c:if>

</c:if>

      <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Search result table" width="100%">
        <tr class="listHeader">
<c:if test="${epChannelAdministratorsView.map.editable}">
          <th id="Checkboxes" width="5%">&nbsp;</th>
</c:if>
          <th id="Name" align="left"><bean-el:message key="ep.header.name" bundle="ep.messages"/></th>
          <th id="Alias" align="left"><bean-el:message key="ep.channel.administrators.header.signinId" bundle="ep.messages"/></th>
          <th id="Phone" align="left"><bean-el:message key="ep.channel.administrators.header.phone" bundle="ep.messages"/></th>
          <th id="Email" align="left"><bean-el:message key="ep.channel.administrators.header.email" bundle="ep.messages"/></th>
<c:if test="${epChannelAdministratorsView.map.editable}">
          <th id="Actions" align="left" width="15%" nowrap><bean-el:message key="ep.header.actions" bundle="ep.messages"/></th>
</c:if>
        </tr>

        <!-- results -->
<c:forEach var="user" items="${epChannelAdministratorsView.map.users}" varStatus="index">
    <c:url var="removeUrl" value="/ep/channelAdministratorRemove.do">
      <c:param name="channelId" value="${epChannelAdministratorsView.map.id}"/>
      <c:param name="userId" value="${user.map.id}"/>
    </c:url>

    <c:choose>
      <c:when test="${(index.count + 1) % 2 == 0}">
        <tr class="listEven">
      </c:when>
      <c:otherwise>
        <tr class="listOdd">
      </c:otherwise>
    </c:choose>

<c:if test="${epChannelAdministratorsView.map.editable}">
          <td headers="Checkboxes" align="center"><input type="checkbox" name="userIds"
            onclick="update(this.form.userIds, this.form.selectAllUsers);"
            value="<c:out value="${user.map.id}"/>"></td>
</c:if>
          <td headers="Name"><c:out value="${user.map.name}"/></td>
          <td headers="Alias"><c:out value="${user.map.signinId}"/></td>
          <td headers="Phone"><c:out value="${user.map.phone}"/></td>
          <td headers="Email"><c:out value="${user.map.email}"/></td>
<c:if test="${epChannelAdministratorsView.map.editable}">
          <td headers="Actions"><a href="<c:out value="${removeUrl}"/>"><c:out value='${removeImg}' escapeXml="false"/></a>
</c:if>
        </tr>
</c:forEach>

<c:if test="${empty epChannelAdministratorsView.map.users}">
        <tr class="listOdd">
          <td align="center" colspan="6">
            <bean:message key="ep.channel.administrators.noFound" bundle="ep.messages"/>
          </td>
        </tr>
</c:if>

      </table>

      <!-- pagination -->
<c:if test="${not empty epChannelAdministratorsView.map.users}">
<%@ include file="/mc/common/pager.jsp" %>
</c:if>

      </form>

<c:if test="${0 == 1}">
      <form method="post">

      <input type="hidden" name="channelId" value="<c:out value="${epChannelAdministratorsView.map.id}"/>"/>
      <input type="hidden" name="ctx.f" value="<c:out value="${requestScope['ctx.f']}"/>"/>

      <div class="pageButtonWrap" align="right">
        <input type="button" name="done" class="inputButton" value="<bean-el:message key='button.done' bundle="ep.messages"/>" onclick="doDone(this.form)">
      </div>

      </form>
</c:if>

  </td></tr>
</table>
